package com.example.support.thread;

import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import com.example.support.spring.SpringContextHolder;

public class ThreadPoolHolder {

	public static ThreadPoolTaskExecutor getTaskExecutor() {
		return ThreadPoolTaskExecutorHolder.INSTANCE;
	}

	public static ThreadPoolTaskScheduler getTaskScheduler() {
		return ThreadPoolTaskSchedulerHolder.INSTANCE;
	}

	private static class ThreadPoolTaskExecutorHolder {
		static final ThreadPoolTaskExecutor INSTANCE = SpringContextHolder.getContext().getBean("applicationTaskExecutor", ThreadPoolTaskExecutor.class);
	}

	private static class ThreadPoolTaskSchedulerHolder {
		static final ThreadPoolTaskScheduler INSTANCE = SpringContextHolder.getContext().getBean("applicationTaskScheduler", ThreadPoolTaskScheduler.class);
	}

}
